import { menus } from '../config.js';

export default {
  namespace: 'sideMenu',
  state: {
    menus: menus,
    currentItem: menus[0]
  },
  reducers: {
    select(state, { currentItem }) {
        return { ...state, currentItem };
    }
  },
  effects: {},
  subscriptions: {
    setup({ dispatch, history }) {
        return history.listen(({ pathname, query }) => {
            const currentItem = menus.find(item => item.key == pathname);
            dispatch({ type: 'select', currentItem: currentItem });
        })
    }
  },
};
